package com.copera.cn.kaka;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.MediaStore;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.copera.cn.kaka.adapter.ShopImageAdapter;
import com.copera.cn.kaka.util.ActionUrls;
import com.copera.cn.kaka.util.AsyncImageLoader;
import com.copera.cn.kaka.util.AsyncImageLoader.ImageCallBack;
import com.copera.cn.kaka.util.HttpUtils;
import com.copera.cn.kaka.util.JsonUtil;
import com.copera.cn.kaka.util.Options;
import com.copera.cn.kaka.util.PictureUtil;
import com.copera.cn.kaka.util.UploadUtil;
import com.copera.cn.kaka.util.Utility;
import com.copera.cn.kaka.vo.ImageVO;
import com.copera.cn.kaka.vo.ShopVo;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * 设置首页
 * 
 * @author Administrator
 *
 */
public class ShopSetHomeActivity extends BaseActivity {
	private RelativeLayout back, r1, r3, r4, valid;
	private ImageView add1, add2, add3, add4, head;
	private TextView text_02, text_03, fxgs, text_04, name, address,
			valid_tv02;
	private ShopImageAdapter shopImageAdapter;
	//private ListView listView;
	private List<ImageVO> vos = new ArrayList<ImageVO>();
	private View footview;
	private String imageId;
	private AsyncImageLoader asyncImageLoader = new AsyncImageLoader();
	
	private boolean bool = false;
	//活动图片
	private TextView tv_01,tv_02,tv_03,tv_04,tv_01_id,tv_02_id,tv_03_id,tv_04_id;
	private ImageView imgset_01,imgset_02,imgset_03,imgset_04;
	private Handler mHandler;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.shop_set_home);
		back = (RelativeLayout) findViewById(R.id.back);
		mHandler = new Handler();
		r1 = (RelativeLayout) findViewById(R.id.r1);
		r3 = (RelativeLayout) findViewById(R.id.r3);
		r4 = (RelativeLayout) findViewById(R.id.r4);
		//footview = getLayoutInflater().inflate(R.layout.foot, null);
		add1 = (ImageView) findViewById(R.id.add1);
		add2 = (ImageView) findViewById(R.id.add2);
		add3 = (ImageView) findViewById(R.id.add3);
		add4 = (ImageView) findViewById(R.id.add4);
		head = (ImageView) findViewById(R.id.head);
		text_02 = (TextView) findViewById(R.id.text_02);
		text_03 = (TextView) findViewById(R.id.text_03);
		fxgs = (TextView) findViewById(R.id.fxgs);
		text_04 = (TextView) findViewById(R.id.text_04);
		name = (TextView) findViewById(R.id.name);
		address = (TextView) findViewById(R.id.address);
		//listView = (ListView) findViewById(R.id.ListView);
		shopId = getAppCustomer().getShop().getShopId();
		valid = (RelativeLayout) findViewById(R.id.valid_01);
		valid_tv02 = (TextView) findViewById(R.id.valid_tv02);
	    tv_01 = (TextView)findViewById(R.id.tv_01);
	    tv_01_id = (TextView)findViewById(R.id.tv_01_id);
	    tv_02_id = (TextView)findViewById(R.id.tv_02_id);
	    tv_03_id = (TextView)findViewById(R.id.tv_03_id);
	    tv_04_id = (TextView)findViewById(R.id.tv_04_id);
        imgset_01 = (ImageView)findViewById(R.id.imgset_01);
        tv_02 = (TextView)findViewById(R.id.tv_02);
        imgset_02 = (ImageView)findViewById(R.id.imgset_02);
        tv_03 = (TextView)findViewById(R.id.tv_03);
        imgset_03 = (ImageView)findViewById(R.id.imgset_03);
        tv_04 = (TextView)findViewById(R.id.tv_04);
        imgset_04 = (ImageView)findViewById(R.id.imgset_04);
		//listView.addFooterView(footview);
		handler = new Handler() {
			@Override
			public void handleMessage(Message msg) {
				if (msg.what == 10) {
					imageId = msg.obj.toString();
					delete();

				}
			}
		};
		DisplayMetrics dm = new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(dm);
		int displayWidth = dm.widthPixels;
		/**shopImageAdapter = new ShopImageAdapter(vos, this, getAppCustomer(),
				handler,displayWidth);
		listView.setAdapter(shopImageAdapter);**/

		initEvent();

		handler = new Handler() {
			@Override
			public void handleMessage(Message msg) {
				switch (msg.what) {

				case ActionUrls.FAILURE:
					Toast.makeText(ShopSetHomeActivity.this, (String) msg.obj,Toast.LENGTH_SHORT).show();
					break;
				}
			}
		};
		reLoad();
		//强制为竖屏 
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		//reLoad();
	}

	public void initEvent() {
		/**listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View view, int arg2,
					long arg3) {
				if (bool) {
					final TextView id = (TextView) view.findViewById(R.id.id);
					Intent intent = null;
					intent = new Intent(ShopSetHomeActivity.this,ShopPhotoDelActivity.class);
					intent.putExtra("imageId", id.getText().toString());
					startActivity(intent);
				}else {
					Message msg = handler.obtainMessage(ActionUrls.FAILURE, "只有店长才能设置店铺宣传图片");
					handler.sendMessage(msg);
				}
			}
		});**/
		imgset_01.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				if (bool) {
					type="1";
					Intent intent = null;
					intent = new Intent(ShopSetHomeActivity.this,ShopPhotoDelActivity.class);
					intent.putExtra("imageId", tv_01_id.getText().toString());
					startActivityForResult(intent, 100);
				}else {
					Message msg = handler.obtainMessage(ActionUrls.FAILURE, "只有店长才能设置店铺宣传图片");
					handler.sendMessage(msg);
				}

			}
		});
		imgset_02.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				if (bool) {
					type="2";
					Intent intent = null;
					intent = new Intent(ShopSetHomeActivity.this,ShopPhotoDelActivity.class);
					intent.putExtra("imageId", tv_02_id.getText().toString());
					startActivityForResult(intent, 100);
				}else {
					Message msg = handler.obtainMessage(ActionUrls.FAILURE, "只有店长才能设置店铺宣传图片");
					handler.sendMessage(msg);
				}

			}
		});
		imgset_03.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				if (bool) {
					type="3";
					Intent intent = null;
					intent = new Intent(ShopSetHomeActivity.this,ShopPhotoDelActivity.class);
					intent.putExtra("imageId", tv_03_id.getText().toString());
					startActivityForResult(intent, 100);
				}else {
					Message msg = handler.obtainMessage(ActionUrls.FAILURE, "只有店长才能设置店铺宣传图片");
					handler.sendMessage(msg);
				}

			}
		});
		imgset_04.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				if (bool) {
					type="4";
					Intent intent = null;
					intent = new Intent(ShopSetHomeActivity.this,ShopPhotoDelActivity.class);
					intent.putExtra("imageId", tv_04_id.getText().toString());
					startActivityForResult(intent, 100);
				}else {
					Message msg = handler.obtainMessage(ActionUrls.FAILURE, "只有店长才能设置店铺宣传图片");
					handler.sendMessage(msg);
				}

			}
		});
		back.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				finish();

			}
		});
		r1.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent();

				intent.setClass(ShopSetHomeActivity.this,
						ShopBasicActivity.class);

				startActivity(intent);
			}
		});
		r3.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				if (bool) {
					Intent intent = new Intent();
					intent.setClass(ShopSetHomeActivity.this,PointPraiseActivity.class);
					startActivity(intent);
				}else {
					Message msg = handler.obtainMessage(ActionUrls.FAILURE, "只有店长才能设置点赞功能");
					handler.sendMessage(msg);
				}
			}
		});
		r4.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				
				if (bool) {
					Intent intent = new Intent();
					intent.setClass(ShopSetHomeActivity.this, ShareActivity.class);
					startActivity(intent);
				}else {
					Message msg = handler.obtainMessage(ActionUrls.FAILURE, "只有店长才能设置分享功能");
					handler.sendMessage(msg);
				}
			}
		});
		add1.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {

				if (bool) {
					type="1";
					Intent intent = new Intent();
					intent.putExtra("type", "1");
					intent.setClass(ShopSetHomeActivity.this,ShopPhotoActivity.class);
					startActivityForResult(intent, 100);
				}else {
					Message msg = handler.obtainMessage(ActionUrls.FAILURE, "只有店长才能设置店铺宣传图片");
					handler.sendMessage(msg);
				}
			}
		});

		add2.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				if (bool) {
					type="2";
					Intent intent = new Intent();
					intent.putExtra("type", "2");
					intent.setClass(ShopSetHomeActivity.this,ShopPhotoActivity.class);
					startActivityForResult(intent, 100);
				}else {
					Message msg = handler.obtainMessage(ActionUrls.FAILURE, "只有店长才能设置店铺宣传图片");
					handler.sendMessage(msg);
				}
			}
		});
		add3.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				if (bool) {
					type="3";
					Intent intent = new Intent();
					intent.putExtra("type", "3");
					intent.setClass(ShopSetHomeActivity.this,ShopPhotoActivity.class);
					startActivityForResult(intent, 100);
				}else {
					Message msg = handler.obtainMessage(ActionUrls.FAILURE, "只有店长才能设置店铺宣传图片");
					handler.sendMessage(msg);
				}
			}
		});
		add4.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				if (bool) {
					type="4";
					Intent intent = new Intent();
					intent.putExtra("type", "4");
					intent.setClass(ShopSetHomeActivity.this,ShopPhotoActivity.class);
					startActivityForResult(intent, 100);
				}else {
					Message msg = handler.obtainMessage(ActionUrls.FAILURE, "只有店长才能设置店铺宣传图片");
					handler.sendMessage(msg);
				}
			}
		});
		// 卡点有效期
		valid.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				if (bool) {
					Intent intent = new Intent();
					intent.setClass(ShopSetHomeActivity.this,TrackValidActivity.class);
					startActivity(intent);
				}else {
					Message msg = handler.obtainMessage(ActionUrls.FAILURE, "只有店长才能设置卡点有效期");
					handler.sendMessage(msg);
				}
				
			}
		});
		//强制为竖屏 
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
	}

	public void loadHeadImage() {

		new AsyncTask<String, Integer, JSONObject>() {

			@Override
			protected JSONObject doInBackground(String... params) {
				JSONObject jsonObj = null;
				try {
					String jsonStr = HttpUtils.get(params[0], getAppCustomer()
							.getHttpClient());

					if (jsonStr != null) {
						jsonObj = new JSONObject(jsonStr);
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
				return jsonObj;
			}

			@Override
			protected void onPostExecute(JSONObject result) {

				if (result != null) {
					try {
						String headImage = result.getString("headImage");
						// 当店铺头像为空值
						if (!"无".equals(headImage)) {
							getAppCustomer().getShop().setHeadImage(headImage);
							Bitmap bitmap = asyncImageLoader.loadBitmap(head,
									ActionUrls.HOST_IMG + headImage,
									getAppCustomer().getHttpClient(),
									new ImageCallBack() {

										@Override
										public void imageLoad(
												ImageView imageView,
												Bitmap bitmap) {
											imageView.setImageBitmap(bitmap);
										}
									});
							if (bitmap != null) {
							
								head.setImageBitmap(bitmap);
							}
						}
					} catch (Exception e) {
						e.printStackTrace();
						if (e.getMessage() != null) {

						}
					}
				}
			}

		}.execute(ActionUrls.URL_LOADHEADIMAGE + "?shopId="
				+ getValue("shopId"));

	}

	private void delete() {

		new AsyncTask<String, Integer, JSONObject>() {

			@Override
			protected JSONObject doInBackground(String... params) {
				JSONObject jsonObj = null;
				try {
					String jsonStr = HttpUtils.get(params[0], getAppCustomer()
							.getHttpClient());

					if (jsonStr != null) {
						jsonObj = new JSONObject(jsonStr);
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
				return jsonObj;
			}

			@Override
			protected void onPostExecute(JSONObject result) {

				loadData();
			}

		}.execute(ActionUrls.URL_DELIMAGE + "?name=" + imageId + "&shopId="
				+ getAppCustomer().getShop().getId());
	}

	private String type, shopId;

	protected void onActivityResult(int requestCode, int resultCode, Intent data) {

		super.onActivityResult(requestCode, resultCode, data);

		if ((requestCode == 100 || requestCode == 200 || requestCode == 300 || requestCode == 400)
				&& resultCode == RESULT_OK && null != data) {

			Uri selectedImage = data.getData();

			String[] filePathColumn = { MediaStore.Images.Media.DATA };

			Cursor cursor = getContentResolver().query(selectedImage,

			filePathColumn, null, null, null);

			cursor.moveToFirst();

			int columnIndex = cursor.getColumnIndex(filePathColumn[0]);

			String picturePath = cursor.getString(columnIndex);

			cursor.close();
			// RelativeLayout imageView = (RelativeLayout)
			// findViewById(R.id.tip);
			BitmapFactory.Options opts = new BitmapFactory.Options();
			opts.inJustDecodeBounds = true;
			Bitmap bp = BitmapFactory.decodeFile(picturePath, opts);

			opts.inSampleSize = Utility.computeSampleSize(opts, -1, 128 * 128);
			opts.inJustDecodeBounds = false;
			/**
			 * BitmapDrawable bd = new BitmapDrawable(Utility.small(
			 * BitmapFactory.decodeFile(picturePath, opts))); BitmapDrawable bd1
			 * = new BitmapDrawable( BitmapFactory.decodeFile(picturePath,
			 * opts));
			 **/

			// imageView.setBackgroundDrawable(bd1);
			if (requestCode == 100) {
				// add1.setBackgroundDrawable(bd);
				add1.setVisibility(View.GONE);
				type = "1";
			} else if (requestCode == 200) {
				// add2.setBackgroundDrawable(bd);
				add2.setVisibility(View.GONE);
				type = "2";
			} else if (requestCode == 300) {
				// add3.setBackgroundDrawable(bd);
				add3.setVisibility(View.GONE);
				type = "3";
			} else if (requestCode == 400) {
				// add4.setBackgroundDrawable(bd);
				add4.setVisibility(View.GONE);
				type = "4";
			} 
			UploadUtil uploadUtil = UploadUtil.getInstance();
			File file = null;

			try {
				file = UploadUtil.saveMyBitmap(bp);
			} catch (IOException e) {

				e.printStackTrace();
			}

			Map<String, String> params = new HashMap<String, String>();
			params.put("shopId", shopId);
			params.put("type", type);
			params.put("flag", "set");
			uploadUtil.uploadFile(file.getAbsolutePath(), "pic",
					ActionUrls.URL_UPLOAD, params);
			ImageVO vo = new ImageVO();
			vo.setFilepath("/images/" + file.getName());
			vo.setName(file.getName());
			vo.setType(type);
			vos.add(vo);
			shopImageAdapter.notifyDataSetChanged();
			

		}else  if (resultCode == 120) {
			ImageLoader imageLoader = ImageLoader.getInstance();
			File f = new File(data.getExtras().getString("filename"));
			if(f.exists()){
				    if(type.equals("1")){
				    	imageLoader.displayImage("file://"+f.getAbsolutePath(), imgset_01, Options.getListOptions());
				    	add1.setVisibility(View.GONE);
				    }else if(type.equals("2")){
				    	imageLoader.displayImage("file://"+f.getAbsolutePath(), imgset_02, Options.getListOptions());
				    	add2.setVisibility(View.GONE);
				    }else if(type.equals("3")){
				    	imageLoader.displayImage("file://"+f.getAbsolutePath(), imgset_03, Options.getListOptions());
				    	add3.setVisibility(View.GONE);
				    }else if(type.equals("4")){
				    	imageLoader.displayImage("file://"+f.getAbsolutePath(), imgset_04, Options.getListOptions());
				    	add4.setVisibility(View.GONE);
				    }
					
			}
		}
		mHandler.postDelayed(new Runnable() {
			@Override
			public void run() {
				reLoad();
			}
		}, 2000);
	}
    public void reLoad(){
    	ShopVo shop = getAppCustomer().getShop();
		if (shop.getId().equals(shop.getShopId())) {
			bool = true;
		}
		if (getAppCustomer().getSetVo() != null) {
			TextView tv_dz = (TextView) findViewById(R.id.tv_dz);
			if ("开放".equals(getAppCustomer().getSetVo().getEnabled())) {
				text_02.setText("点赞"
						+ getAppCustomer().getSetVo().getTotalCount() + "次送出"
						+ getAppCustomer().getSetVo().getPresenterCount()
						+ "个卡点.");
				text_03.setText("每用户每天只能点赞"
						+ getAppCustomer().getSetVo().getDayCount() + "次.");
				text_02.setVisibility(View.VISIBLE);
				text_03.setVisibility(View.VISIBLE);
				tv_dz.setVisibility(View.GONE);
			} else {
				text_02.setVisibility(View.GONE);
				text_03.setVisibility(View.GONE);
				tv_dz.setVisibility(View.VISIBLE);
			}
		}
		if (getAppCustomer().getShareSetVo() != null) {
			TextView tv_fx = (TextView) findViewById(R.id.tv_fx);
			if ("开放".equals(getAppCustomer().getShareSetVo().getEnabled())) {
				String dayCount,presenterCount,totalCount;
				dayCount=getAppCustomer().getShareSetVo().getDayCount();
				presenterCount=getAppCustomer().getShareSetVo().getPresenterCount();
				totalCount=getAppCustomer().getShareSetVo().getTotalCount();
				fxgs.setText("分享"
						+ totalCount
						+ "次送出"
						+ presenterCount
						+ "个卡点.");
				text_04.setText("每用户每天只能分享"
						+ dayCount + "次.");
				fxgs.setVisibility(View.VISIBLE);
				text_04.setVisibility(View.VISIBLE);
				tv_fx.setVisibility(View.GONE);
			} else {
				fxgs.setVisibility(View.GONE);
				text_04.setVisibility(View.GONE);
				tv_fx.setVisibility(View.VISIBLE);
			}
		}
		name.setText(getAppCustomer().getShop().getShopName());
		address.setText(getAppCustomer().getShop().getAddress());
		if (!"0".equals(getAppCustomer().getShop().getValidDate())) {
			valid_tv02.setText(getAppCustomer().getShop().getValidDate() + "个月");
		}
		loadHeadImage();
		loadData();
    }
	@Override
	protected void onResume() {
		reLoad();
		super.onResume();
	}

	private String types;// 当前已上传的图片序号

	private List<ImageVO> loadImage() throws ClientProtocolException,
			IOException, JSONException {

		String url = ActionUrls.URL_SHOPIMAGE + "?shopId="
				+ getAppCustomer().getShop().getShopId();
		String json = HttpUtils.get(url, getAppCustomer().getHttpClient());
		JSONObject jo = new JSONObject(json);
		JSONArray ts = jo.getJSONArray("list");
		List<ImageVO> list = JsonUtil.toShopImageVo(ts);
		types = jo.getString("types");

		return list;
	}

	// 加载图片
	private void loadData() {
		
		new AsyncTask<String, Integer, List<ImageVO>>() {

			@Override
			protected List<ImageVO> doInBackground(String... params) {

				try {
					List<ImageVO> images = loadImage();

					return images;
				} catch (Exception e) {
					e.printStackTrace();
				}
				return null;
			}

			@Override
			protected void onPostExecute(List<ImageVO> images) {

				if (images != null && images.size() > 0) {
					try {

						tv_01.setText("");
						imgset_01.setImageBitmap(null);
						tv_01.setVisibility(View.GONE);
						imgset_01.setVisibility(View.GONE);
						tv_02.setText("");
						imgset_02.setImageBitmap(null);
						tv_02.setVisibility(View.GONE);
						imgset_02.setVisibility(View.GONE);
						tv_03.setText("");
						imgset_03.setImageBitmap(null);
						tv_03.setVisibility(View.GONE);
						imgset_03.setVisibility(View.GONE);
						tv_04.setText("");
						imgset_04.setImageBitmap(null);
						tv_04.setVisibility(View.GONE);
						imgset_04.setVisibility(View.GONE);
						ImageLoader imageLoader = ImageLoader.getInstance();
		  				if (images != null && images.size()>0) {
		  				
		  					for(int i=0;i<images.size();i++){
		  						if(i==0){
		  							tv_01.setText(images.get(0).getTitle());
		  							imageLoader.displayImage(ActionUrls.HOST_IMG+images.get(0).getFilepath(), imgset_01, Options.getListOptions());
		  							
		  							tv_01.setVisibility(View.VISIBLE);
									imgset_01.setVisibility(View.VISIBLE);
									tv_01_id.setText(images.get(0).getId());
		  						}else if(i==1){
		  							tv_02.setText(images.get(1).getTitle());
		  							imageLoader.displayImage(ActionUrls.HOST_IMG+images.get(1).getFilepath(), imgset_02, Options.getListOptions());
		  							tv_02.setVisibility(View.VISIBLE);
									imgset_02.setVisibility(View.VISIBLE);
									tv_02_id.setText(images.get(1).getId());
		  						}else if(i==2){
		  							tv_03.setText(images.get(2).getTitle());
		  							imageLoader.displayImage(ActionUrls.HOST_IMG+images.get(2).getFilepath(), imgset_03, Options.getListOptions());
		  							tv_03.setVisibility(View.VISIBLE);
									imgset_03.setVisibility(View.VISIBLE);
									tv_03_id.setText(images.get(2).getId());
		  						}else{
		  							tv_04.setText(images.get(3).getTitle());
		  							imageLoader.displayImage(ActionUrls.HOST_IMG+images.get(3).getFilepath(), imgset_04, Options.getListOptions());
		  							tv_04.setVisibility(View.VISIBLE);
									imgset_04.setVisibility(View.VISIBLE);
									tv_04_id.setText(images.get(3).getId());
		  						}
		  						
		  					}
		  					
		  				}

						if (!types.equals("无")) {
							if (types.indexOf("1") != -1) {
								add1.setVisibility(View.GONE);
							} else {
								add1.setVisibility(View.VISIBLE);
							}
							if (types.indexOf("2") != -1) {
								add2.setVisibility(View.GONE);
							} else {
								add2.setVisibility(View.VISIBLE);
							}
							if (types.indexOf("3") != -1) {
								add3.setVisibility(View.GONE);
							} else {
								add3.setVisibility(View.VISIBLE);
							}
							if (types.indexOf("4") != -1) {
								add4.setVisibility(View.GONE);
							} else {
								add4.setVisibility(View.VISIBLE);
							}
						}

					} catch (Exception e) {
						e.printStackTrace();
						if (e.getMessage() != null) {

						}
					}
				} else {
					add1.setVisibility(View.VISIBLE);
					add2.setVisibility(View.VISIBLE);
					add3.setVisibility(View.VISIBLE);
					add4.setVisibility(View.VISIBLE);
					tv_01.setText("");
					imgset_01.setImageBitmap(null);
					tv_01.setVisibility(View.GONE);
					imgset_01.setVisibility(View.GONE);
					tv_02.setText("");
					imgset_02.setImageBitmap(null);
					tv_02.setVisibility(View.GONE);
					imgset_02.setVisibility(View.GONE);
					tv_03.setText("");
					imgset_03.setImageBitmap(null);
					tv_03.setVisibility(View.GONE);
					imgset_03.setVisibility(View.GONE);
					tv_04.setText("");
					imgset_04.setImageBitmap(null);
					tv_04.setVisibility(View.GONE);
					imgset_04.setVisibility(View.GONE);
				}
				//Utility.setListViewHeightBasedOnChildren(listView);
				//shopImageAdapter.notifyDataSetChanged();
				//listView.setFocusable(false);
				
				
			}

		}.execute("");
	}

}
